package com.s2paganini.text
{
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;		

	/**
	 * @author siLvio paganini | s2paganini.com
	 * @purpose Default TextField
	 */

	public class DefaultTextField extends TextField 
	{
		public function DefaultTextField(defaultStyle : TextFormat = null, antiAtias : Boolean = true, _dynamic: Boolean = true, _wordWrap : Boolean = false, _multiline : Boolean = false)
		{
			selectable = !_dynamic;
			antiAliasType = (antiAtias) ? AntiAliasType.ADVANCED : AntiAliasType.NORMAL;
			type = (_dynamic) ? TextFieldType.DYNAMIC : TextFieldType.INPUT;
			autoSize = TextFieldAutoSize.LEFT;
			embedFonts = true;
			if(defaultStyle) defaultTextFormat = defaultStyle;
			wordWrap = _wordWrap;
			multiline = _multiline;
		}
				
		public function cropText():void{
			var destl: Number = 0;
			var tempText : String = text;
			
			for (var i:int = 0; i<tempText.length; i++){
				htmlText = tempText.substr(0, i) + "...";
				if(textHeight > height){
					destl = i - 1;
					break;	
				}	
			}
			
			if(destl > 0){
				htmlText = tempText.substr(0, destl) + "...";	
			} else {
				htmlText = tempText;
			}
		}
	}
}
